package com.xyht.sca_s.student_manage_system.modules.wx.config;

import com.xyht.sca_s.student_manage_system.modules.wx.entity.WxMpPropertiesEntity;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class WxMpConfig {
    @Autowired
    private WxMpPropertiesEntity wxMpPropertiesEntity;

    @Bean
    public WxMpConfigStorage wxMpConfigStorage() {
        WxMpDefaultConfigImpl config = new WxMpDefaultConfigImpl();
        config.setAppId(wxMpPropertiesEntity.getAppId());
        config.setSecret(wxMpPropertiesEntity.getAppSecret());
        config.setToken(wxMpPropertiesEntity.getToken());
        config.setAesKey(wxMpPropertiesEntity.getAes());
        return config;
    }

    @Bean
    public WxMpService wxMpService(WxMpConfigStorage wxMpConfigStorage) {
        WxMpService service = new WxMpServiceImpl();
        service.setWxMpConfigStorage(wxMpConfigStorage);
        return service;
    }

}
